//logs.js
const util = require('../../utils/util.js')
const appid = 'wxef012d29b5995355';
const secret = '0f615a3d8ea63135aff3b46b32cca842';
const env = 'qr-cs8dp';
const name = 'test';
Page({
  data: {
    logs: []
  },
  onLoad: function () {
  },

  getAtoken() {
    let pro = new Promise((resolve, reject) => {
      let url = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`;
      qq.request({
        url,
        success: res => {
          resolve(res.data.access_token)
        }
      })
    });

    return pro;
  },

  test(e) {
    this.getAtoken().then(res => {
      //console.log(res);
      let access_token = res;
      let url = `https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=${access_token}&env=${env}&name=${name}`;

      qq.request({
        url,// 仅为示例，并非真实的接口地址
        method:'post',
        data: {
          x: 5,
          y: 6
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success(res) {
          //console.log(res);
          let data=JSON.parse(res.data.resp_data);
          console.log(data);
        }
      })
    })
  }
})
